import React, { Component } from 'react'
import { Input, Button } from 'antd'
import { postLogin } from '@/utils/api/api'

export default class componentName extends Component {
  state = {
    username: '',
    password: ''
  }
  render() {
    const { username, password } = this.state
    return (
      <div>
        账号：<Input value={username} onChange={(e) => this.handleInputUser(e)} />
        账号：<Input value={password} onChange={(e) => this.handleInputPwd(e)} />
        <Button onClick={() => this.handleBtnClick()}>登陆</Button>
      </div>
    )
  }

  handleInputUser(e) {
    this.setState({
      username: e.target.value
    })
    // this.setState(() => {})
  }
  handleInputPwd(e) {
    this.setState({
      password: e.target.value
    })
  }

  async handleBtnClick() {
    console.log(this.state, 'state')
    let data = await postLogin(this.state);
    if (data.code === 0) {
      window.sessionStorage.setItem('token', data.token)
      this.props.history.push('/homeIndex/table')
    }
  }

}
